Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve display of code-blocks in README.md #18

Merged
merged 9 commits into from
Sep 15, 2021
Merged

Improve display of code-blocks in README.md #18

merged 9 commits into from
Sep 15, 2021

Conversation

Alhadis
Copy link
Contributor

@Alhadis Alhadis commented Sep 8, 2021

This PR combines a bunch of cosmetic enhancements to the readme file, plus an extra example to showcase how bat can be used to add syntax highlighting.

The latter includes a screenshot that's uploaded as a file attachment to #17 (comment), since I didn't feel comfortable asking the author to accept a 19 KB blob of uncompressible image data in addition to a bunch of lightweight improvements.

README.md Show resolved Hide resolved
README.md Outdated
### Syntax highlighting with [`bat`](https://github.com/sharkdp/bat)

```console
$ curl -sL https://mdn.io/Array | htmlq '#description ~ *' | bat -l html
Copy link

@jihchi jihchi Sep 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting an empty result:

2021-09-09 08-42-39

This is what I get when I fetch https://mdn.io/Array:

curl -sL https://mdn.io/Array | bat -l html
───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ STDIN
───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ <html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'><meta name='referrer' content='origin'><me
       │ ta name='robots' content='noindex, nofollow'><meta http-equiv='refresh' content='0; url=/l/?uddg=https%3A%2F%2Fdeveloper.
       │ mozilla.org%2Fen%2DUS%2Fdocs%2FWeb%2FJavaScript%2FReference%2FGlobal_Objects%2FArray&rut=8e8be647aa3a967ad702ca33e4af9333
       │ 8c0706ded1acd5ea363e0e2326dde70c'></head><body><script language='JavaScript'>function ffredirect(){window.location.replac
       │ e('/l/?uddg=https%3A%2F%2Fdeveloper.mozilla.org%2Fen%2DUS%2Fdocs%2FWeb%2FJavaScript%2FReference%2FGlobal_Objects%2FArray&
       │ rut=8e8be647aa3a967ad702ca33e4af93338c0706ded1acd5ea363e0e2326dde70c');}setTimeout('ffredirect()',100);</script></body></
       │ html>
───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Instead of https://mdn.io/Array, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array works for me:

curl -sL https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array | htmlq '#description ~ *' | bat -l html
───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ STDIN
───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ <div><p>Arrays are list-like objects whose prototype has methods to perform traversal and mutation operations. Neither th
       │ e length of a JavaScript array nor the types of its elements are fixed. Since an array's length can change at any time, a
       │ nd data can be stored at non-contiguous locations in the array, JavaScript arrays are not guaranteed to be dense; this de
       │ pends on how the programmer chooses to use them. In general, these are convenient characteristics; but if these features
       │ are not desirable for your particular use, you might consider using typed arrays.</p>
...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 That's odd. Seems like mdn.io doesn't respond to page requests if you haven't set a User-Agent header:

curl -qsL -A 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)' https://mdn.io/Array

I didn't notice this because I have my ~/.curlrc file configured to send a convincing-looking User-Agent header with each request, since some webmasters configure their servers to block what they perceive to be automated traffic.

I wanted the example to be short-and-sweet, hence I chose a short but practical URL. 😞 Should I change it?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for me!

curl -qsL -A 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)' https://mdn.io/Array

I do like your short-and-sweet example, but I'm afraid that most people wouldn't have User-Agent in their ~/.curlrc and they might be confused when they see "empty".

How about example.com? for example:

$ curl -s example.com | htmlq 'body' | bat -l html
───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ STDIN
───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ <body>
   2   │ <div>
   3   │     <h1>Example Domain</h1>
   4   │     <p>This domain is for use in illustrative examples in documents. You may use this
   5   │     domain in literature without prior coordination or asking for permission.</p>
   6   │     <p><a href="https://www.iana.org/domains/example">More information...</a></p>
   7   │ </div>
   8   │
   9   │
  10   │ </body>
───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done and done! I've updated the screenshot to match, too.

README.md Outdated Show resolved Hide resolved
@mgdm
Copy link
Owner

mgdm commented Sep 12, 2021

Hey! Thanks for your work here, that looks better. I've since made a couple of edits to the README which have caused a conflict, do you mind rebasing? I can do that later if you prefer.

@Alhadis
Copy link
Contributor Author

Alhadis commented Sep 13, 2021

Conflicts resolved.

@Alhadis
Copy link
Contributor Author

Alhadis commented Sep 15, 2021

@mgdm As an afterthought, I also added permalinks to the headings you added in 014ae25. Hope that's okay.

@mgdm mgdm merged commit 1fbb818 into mgdm:master Sep 15, 2021
@mgdm
Copy link
Owner

mgdm commented Sep 15, 2021

That's great, thanks so much!

@Alhadis Alhadis deleted the readme-polishes branch September 15, 2021 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants